#include "stdafx.h"
#include "WndProc.h"
#include "ReSizeGLScene.h"
#include "DrawGLScene.h"

extern bool	g_bActive;
extern bool	g_ArrKeys[256];

extern cWglARTK g_wglARTK;
extern CSpeechToText g_speechToText;
extern HDC	g_hDC;
extern CGlobe g_global;

LRESULT CALLBACK WndProc(	HWND	hWnd,			// Handle For This Window
						 UINT	uMsg,			// Message For This Window
						 WPARAM	wParam,			// Additional Message Information
						 LPARAM	lParam)			// Additional Message Information
{
	// sound message
	g_speechToText._DealMessage(uMsg);

	// --------------------

	switch (uMsg)									// Check For Windows Messages
	{
		// --------------------
		// by aicro
	case WM_PAINT:
		DrawGLScene();					// Draw The Scene
		SwapBuffers(g_hDC);				// Swap Buffers (Double Buffering)
		break;
		// --------------------

	case WM_ACTIVATE:							// Watch For Window Activate Message
		{
			if (!HIWORD(wParam))					// Check Minimization State
			{
				g_bActive=TRUE;						// Program Is Active
			}
			else
			{
				g_bActive=FALSE;						// Program Is No Longer Active
			}

			return 0;								// Return To The Message Loop
		}

	case WM_SYSCOMMAND:							// Intercept System Commands
		{
			switch (wParam)							// Check System Calls
			{
			case SC_SCREENSAVE:					// Screensaver Trying To Start?
			case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?
				return 0;							// Prevent From Happening
			}
			break;									// Exit
		}

	case WM_CLOSE:								// Did We Receive A Close Message?
		{
			g_global.bStop = true;
			WaitForSingleObject(g_global.hStop, INFINITE);
			PostQuitMessage(0);						// Send A Quit Message
			return 0;								// Jump Back
		}

	case WM_KEYDOWN:							// Is A Key Being Held Down?
		{
			//int key = (int) wParam;
			//switch(key)
			//{
			//case VK_UP:	
			//	g_wglARTK.addViewScaleFactor( -0.01 );
			//	g_global.fScale = g_wglARTK.getCurrentScale();
			//	break;

			//case VK_DOWN:	
			//	g_wglARTK.addViewScaleFactor(  0.01 );
			//	g_global.fScale = g_wglARTK.getCurrentScale();
			//	break;		
			//}
			g_ArrKeys[wParam] = TRUE;					// If So, Mark It As TRUE
			return 0;								// Jump Back
		}

	case WM_KEYUP:								// Has A Key Been Released?
		{

			g_ArrKeys[wParam] = FALSE;					// If So, Mark It As FALSE
			return 0;								// Jump Back
		}

	case WM_SIZE:								// Resize The OpenGL Window
		{
			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height
			return 0;								// Jump Back
		}

	}

	// Pass All Unhandled Messages To DefWindowProc
	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}


